﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Jinjia.Approve.Entity.Entity.JJFlow;
using Jinjia.Approve.Model.Input.JJFlow;
using Jinjia.Approve.Model.VM.JJFlow;
using Jinjia.Approve.Model.VM.JJFlow.DTO;
using Jinjia.Approve.Model.VM.JJFlow.Request;
using Jinjia.Core.BaseInfrastructure.StorageModel.Model;

namespace Jinjia.Approve.IService.JJFlow
{
    public interface IJJFlowInstanceService
    {
        Task<JjFlowInstanceVM> GetById(int instance_id);

        /// <summary>
        /// 此业务是否存在待审批或已经完成的审批记录
        /// </summary>
        /// <param name="modular_key">模块Key</param>
        /// <param name="template_id">审批流模板ID</param>
        /// <param name="biz_order_id">业务ID</param>
        /// <returns></returns>
        Task<List<JjFlowInstanceVM>> IsExist(string modular_key, int template_id, string biz_order_id);

        /// <summary>
        /// 检测用户节点权限
        /// </summary>
        /// <param name="node_id"></param>
        /// <param name="template_id"></param>
        /// <param name="user_id"></param>
        /// <param name="instance_id"></param>
        /// <returns></returns>
        Task<bool> CheckNodeUser(int node_id, int template_id, int user_id, int instance_id);


        /// <summary>
        /// 检测节点是否已操作
        /// </summary>
        /// <param name="node_id"></param>
        /// <param name="user_id"></param>
        /// <param name="instance_id"></param>
        /// <returns>true 已存在, false不存在</returns>
        Task<bool> CheckNodeTrack(int node_id, int user_id, int instance_id);

        /// <summary>
        /// 获取 Instance
        /// </summary>
        /// <param name="modular_key">模块Key</param>
        /// <param name="biz_order_id">业务ID</param>
        /// <returns></returns>
        Task<JjFlowInstanceVM> GetInstanceInfo(string modular_key, string biz_order_id);

        /// <summary>
        /// 新增或修改
        /// </summary>
        /// <param name="data"></param>
        /// <returns>主键id</returns>
        Task<int> Save(JjFlowInstanceVM data);

        Task SaveInstanceForm(int instance_id, Dictionary<string, string> dic, List<jj_flow_dictcode> dicCodeList);

        /// <summary>
        /// 保存节点审批人员
        /// </summary>
        /// <param name="instance_id"></param>
        /// <param name="template_id"></param>
        /// <param name="biz_order_id"></param>
        /// <param name="start_user"></param>
        /// <returns></returns>
        Task SaveInstanceEmp(int instance_id, int template_id, string biz_order_id, int start_user, Dictionary<string, string> dic = null);

        /// <summary>
        /// 查询 待我审批
        /// </summary>
        /// <param name="modular_key">前端模块key</param>
        /// <param name="user_id">当前用户</param>
        /// <returns></returns>
        Task<List<string>> GetUserBizOrderId(string modular_key, int user_id);

        /// <summary>
        /// 首页-待办 汇总
        /// </summary>
        /// <param name="currentUserId"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        Task<PageListSearchResultVM<MyTodoListOverview>> GetMyTodoListOverview(int currentUserId, SearchConditionBaseInput input);
        /// <summary>
        /// 首页 待办 汇总的总条数
        /// </summary>
        /// <param name="currentUserId"></param>
        /// <returns></returns>
        Task<int> GetMyTodoListCount(int currentUserId);
        /// <summary>
        /// 首页 -待办 详情
        /// </summary>
        /// <param name="currentUserId"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        Task<PageListSearchResultVM<MyTodoListDetail>> GetTodoListDetailForCurrentUser(int currentUserId, GetToDoListDetailByTab input);
        /// <summary>
        /// 通过url获取信息
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        Task<IReadOnlyList<SearchByUrlResponse>> SearchByUrl(string url);
        /// <summary>
        /// 查询审批列表
        /// </summary>
        /// <param name="modular_key"></param>
        /// <param name="biz_order_id"></param>
        /// <returns></returns>
        Task<List<JjFlowInstanceVM>> GetInstanceList(string modular_key, string biz_order_id);

        /// <summary>
        /// 我已审批操作的数据
        /// </summary>
        /// <param name="system_key"></param>
        /// <param name="big_modular_key"></param>
        /// <param name="modular_key"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        Task<List<string>> GetUserProcessedBizOrderId(string system_key, string big_modular_key, string modular_key, int user_id);

        /// <summary>
        /// 获取我提交审核的数据
        /// </summary>
        /// <param name="system_key"></param>
        /// <param name="big_modular_key"></param>
        /// <param name="modular_key"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        Task<List<string>> GetUserCreateApplyBizOrderId(string system_key, string big_modular_key, string modular_key, int user_id);

        /// <summary>
        /// 审批单列表
        /// </summary>
        /// <param name="searchCondition"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        Task<PageListSearchResultVM<JJInstanceViewModel>> GetInstancePageList(JJInstanceSearchCondition searchCondition, int user_id);

        /// <summary>
        /// 条件获取审批列表
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        Task<List<JjFlowInstanceVM>> GetInstanceListAsync(Expression<Func<jj_flow_instance, bool>> expression);
    }
}